<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="components/com_town/public/css/ie7.css" />    
<![endif]-->

<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="components/com_town/public/css/ie8.css" />    
<![endif]-->

<!--[if IE 9]>
<link rel="stylesheet" type="text/css" href="components/com_town/public/css/ie9.css" />    
<![endif]-->
<script src="../media/system/js/mootools-core.js" type="text/javascript"></script>
<script src="../media/system/js/core.js" type="text/javascript"></script>
<form action="index.php?option=com_town" method="post" name="adminForm" id="adminForm">
	<fieldset id="filter-bar">
		<div class="filter-search fltlft">
			<label class="filter-search-lbl" for="keyword" style="line-height:20px;">フィルタ</label>
			<input type="text" class="inputbox medium" name="keyword" id="keyword" value="<?php echo JRequest::getVar('keyword') ?>" />
            <label class="filter-search-lbl" for="pref" style="line-height:20px;">都道府県</label>
            <select name="pref" id="pref" class="inputbox medium">
                <option value='0'>指定しない</option>    
                <?php 
                    foreach($this->getModel()->getPREF() as $area){
                        $selected = JRequest::getVar('pref') == $area->PREF_CODE ? 'selected' : '';
                        echo "<option $selected value='$area->PREF_CODE'>$area->PREF_NAME</option>";
                    }
                 ?>    
            </select>
			<button id="search" type="button" onclick="Joomla.submitbutton('search')">検索</button>
			<!--<button type="button" id="clear">クリア</button>-->
            <button type="button" class="button" onclick="
                        document.id('keyword').value='';
                        document.id('pref').value='0';this.form.submit();">クリア</button>
        </div>
	</fieldset>
	<div class="clr"> </div>
	<table class="adminlist">
		<thead>
			<tr>
				<th width="5%">
				    <input type="checkbox" name="checkall-toggle" value="" title="Check All" onclick="Joomla.checkAll(this)"/>
				</th>
				<th width="8%">
					<label class="labelth">市町村ID</label>				
                </th>
				<th width="20%">
					<label class="labelth">市町村名</label>   				
                </th>
				<th width="7%">
					<label class="labelth">人口</label>   				
                </th>
				<th width="30%">
					<label class="labelth">住所</label>   			
                </th>
                <th width="10%">
					<label class="labelth">同期済/未同期</label>   
                </th>
                <th width="10%">
                    <label class="labelth">公開済/一時保存中</label>    	
                </th>
			</tr>
		</thead>
		
		<tbody id="result">
		  <?php
            $result = $this->result;
            if(!empty($result)){
                foreach ($result as $key=>$town){
                $row_cls = $key % 2;
                ($town->TOWN_WEBF) == 1 ? $savetemp = '公開済' : $savetemp = '一時保存中'; //Check flag save temp or save
                ($town->TOWN_DBSY) == 1 ? $dbsy= '同期済' : $dbsy = '未同期'; //Check flag save temp or save
                echo "<tr class='row$row_cls'>
            			<td class='center'><input type='checkbox' id='cb0' name='cid[]' value='$town->TOWN_CODE' onclick='Joomla.isChecked(this.checked);'/></td>
            			<td class='center'><a href='index.php?option=com_town&task=edit&cid=$town->TOWN_CODE'>$town->TOWN_CODE</a></td>
            			<td class='left'><a href='index.php?option=com_town&task=edit&cid=$town->TOWN_CODE'>$town->TOWN_NAME</a></td>
                        <td class='right'>$town->TOWN_POPU</td>
                        <td class='left'>$town->TOWN_ADD1</td>
                        <td class='center'>$dbsy</td>
                        <td class='center'>$savetemp</td>
                    </tr>";
                }
            }
            else{
                echo "<tr class='row0'>
                            <td colspan='7' class='center'>データは見つかりませんでした</td>
                    </tr>";
            }
        ?>	  
		</tbody>
	</table>
    <table  style="margin: 0 auto;">
        <tfoot>
			<tr>
				<td colspan="15">
					<?php echo $this->pagination->getListFooter(); ?>
                </td>
			</tr>
		</tfoot>
    </table>
    <!-- <input type="submit" value="同期" style="width: 75px;float:right;" onclick="Joomla.submitbutton('dongbo_csv_town');document.id('task').value='';"/> -->
		<input type="hidden" name="task" value="">
		<input type="hidden" name="boxchecked" value="0">
</form>
<script>
    jq('#clear').click(function(event){
        jq('#keyword').val("");
        jq('#pref').val("0");
    });
    
    //Check message delete information TOWN
    Joomla.submitbutton = function(task){
    if(task == 'remove'){
        if(!confirm('選択したデータを削除します。よろしいですか？')){
            return false;
        }
    }
    Joomla.submitform(task, document.getElementById('adminForm'));
 }
</script>